procedure search;
var i,t:longint;
begin
t:=1;
for i:=2 to n do
  if d[i]<d[t] then t:=i;
end.

procedure dist;
var i,u:longint; t:set of 1..n;
begin
for i:=1 to n do d[i]:=a[s][i];
d[s]:=0;
t:=[1..n]-[s];
while t<>[] do begin
  search;
  u:=k;
  t:=t-[u];
  for i:=1 to n do 
    if i in t then d[i]:=min(d[i],d[u]+a[u][i]);
end;
end;

procedure way(s,t:longint);
var v,u:longint;
begin
inc(cur);
st[cur]:=t;
v:=t;
while v<>s do begin
  u:=1;
  while d[v]<>d[u]+a[u][v] do inc(u);
  inc(cur);
  st[cur]:=u;
  v:=u;
end;
end;